import axios from 'axios';

//创建axios 实例

const request =axios.create({
    baseURL: process.env.VUE_APP_BASE_URL,
    timeout:  1000 * 12
    
})

// 设置post请求头
request.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'

/**
 * 请求拦截器
 * 
 */

request.interceptors.request.use(config => {
// Do something before response is sent
const token =localStorage.token;
if(token){
    config.headers.Authorization = token; 
    // config.headers.Authorization = "KpBvgSaOv9E2iH4Cd6ZsPP0KeZo2RaSIZjbjFS9rVprWUayeO9Zkf/yHoy+Ue0VD2MA6ff6E9m5UjkD/jSOnMsyy2iYjxyiuxK1Un3TB490dFSR87o521bYDjfi2ShPv/L1GWnR4Jj+hHHqxSs+XrecZ2RnNrnQABh3Ao0gA0JykA5auitu2+tzioZL5gJlqbezB69CgBTro+WUP6IhZYA=="
}
return config;
},error => {
// Do something with response error
return Promise.reject(error);
});



/**
 * 响应拦截器
 * 
 */
request.interceptors.response.use(response => {
// Do something before response is sent
return response;
},error => {
// Do something with response error
return Promise.reject(error);
});


export default{
    install(app){
      app.config.globalProperties.$http = request
    }
}